#_*_coding:utf-8_*_
import boto
import boto.s3.connection
import functions.mfun as F
from multiprocessing import Pool

import os
from time import sleep,time

conn = boto.connect_s3(
            aws_access_key_id = '4C3Z7YH7CCN4MV7MZBUM',
            aws_secret_access_key = 'ASuvrSgfIearbU2VnYnNleecgLstRBHw1B8lE7QZ',
            host = 's3.ceph.com',is_secure=False,
            calling_format = boto.s3.connection.OrdinaryCallingFormat())


if __name__ == '__main__':
	print '######## Init Data '
	bucketname = 'speedtest'
	bucket = conn.get_bucket(bucketname)
	listfile = os.listdir('./tmp') 
	#print listfile
	print '######## Start to Run'
	#########Processes###########
	start = time()
	rs = []
	pro_num = 5
	p = Pool(processes=pro_num)
	for f in listfile:	
	    #######(filepath, keyname, bucket, threadcnt )
	    res = p.apply_async(F.upload_file_multipart,args=('tmp/%s'%f,f,bucket,8))
	    rs.append(res)
	p.close()
	p.join()
	end = time()
	#########Results#########
	print '######## Dealing Result'
	print end-start
